﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AbpVnext_Module;
using Ebusiness_Domain.IRepository;
using Ebusiness_Domain.Model;
using Ebusiness_EntityFrameWork.DBContext;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;

namespace Ebusiness_EntityFrameWork
{
    /// <summary>
    /// 保存商品的方法(仓储只能操作聚合根，不能操作聚合根以下的实体)
    /// </summary>
    [Dependency(ServiceLifetime.Transient)]
    public class ProductRepository : IProductRepository
    {
        public EbusinessDbContext Context { get; set; }

        public ProductRepository(EbusinessDbContext context)
        {
            Context = context;
        }

        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Product> GetProducts()
        {
            return Context.Product.Where(x => x.Id == 10).ToList();
        }

        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="product"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void InsertProduct(Product product)
        {
            Context.Product.Add(product);
            Context.SaveChanges();
        }

        /// <summary>
        /// 添加商品图片图片
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public bool InsertProductImage(Product product)
        {
            Context.Product.Add(product);
            Context.SaveChanges(true);
            return true;
        }
    }
}
